<script src="/include/calendar/calendar.js"></script>
<style type="text/css">
.operate a {
	margin-right: 5px;
	padding: 0 5px;
}
.alert.alert-info p {
	margin-top: 0px;
}
.panel-body a {
	color: inherit;
}
</style>
<div class="pageheader">
	<h2>
		<i class="fa fa-sitemap"></i>办公管理
	</h2>
	<div class="breadcrumb-wrapper">
		<span class="label">你所在的位置：</span>
		<ol class="breadcrumb">
			<li><a href="/index">ERP管理系统</a></li>
			<li>办公管理</li>
			<li class="active">我的任务</li>
		</ol>
	</div>
</div>
<div class="contentpanel">
	<div class="main">
		<form id="search-form" class="form-inline" method="get" action="" style="margin-bottom: 10px;">
			<div class="form-group">
				<input placeholder="标题" type="text" name="title" value="<?php echo $this->title;?>" class="form-control">
			</div>
			<div class="form-group">
				<!-- <label for="Statu">状态</label>  -->
				<select class='form-control' name='statu'>
					<option value='' <?php if($this->statu == ''){echo 'selected="selected"';}?>>选择状态</option>
					<option value='0' <?php if($this->statu == '0'){echo 'selected="selected"';}?>>未开始</option>
					<option value='1' <?php if($this->statu == '1'){echo 'selected="selected"';}?>>进行中</option>
					<option value='2' <?php if($this->statu == '2'){echo 'selected="selected"';}?>>已完成</option>
				</select>
			</div>
			<div class="form-group">
				<label for="date">日期:</label>
				<input class="form-control" type="text" name="starttime" onclick="new Calendar().show(this);" readonly="readonly" value="<?php echo $this->starttime;?>"> 
				至<input class="form-control" type="text" name="endtime" onclick="new Calendar().show(this);" readonly="readonly" value="<?php echo $this->endtime;?>">
			</div>
			<button type="submit" class="btn btn-primary">搜索</button>
		</form>
		<table id="order-log" class="table table-bordered table-hover">
			<thead>
				<tr>
					<th width="25%">摘要</th>
					<th>网站</th>
					<th>任务来自</th>
					<th>指派时间</th>
					<th>优先级</th>
					<th>工时</th>
					<th>进度</th>
					<th>状态</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
                <?php if ($this->list):?>
                <?php foreach ($this->list as $v):?>
                <tr>
					<td><?php echo $v['title'];?></td>
					<td><?php echo $v['site'];?></td>
					<td><?php echo $v['need_name'];?></td>
					<td><?php echo $v['asign_time'];?></td>
					<td><?php echo $v['priority']==0 ? '默认等待':($v['priority']==1 ? '比较重要':'十分紧急');?></td>
					
					<td><?php echo '已用'.$v['time'].'个工时';?></td>
					<td><?php echo $v['progress'].'%';?></td>
					<?php if(intval($v['statu'])==0){?>
					<td class="statu">
					    <span class="label label-warning">未开始</span>
					</td>
					<td class="operate">
					    <a class="btn btn-default btn-sm" title="开始任务" href="javascript:void(0);" onclick="begin(<?php echo $v['id']; ?>, this)">开始</a> 
						<a class="btn btn-default btn-sm" title="查看任务" href="javascript:void(0);" onclick="view(<?php echo $v['id']; ?>)">查看</a>
					    <a class="btn btn-default btn-sm" title="任务备注" href="/office/memo?id=<?php echo $v['id'];?>">备注</a>
					</td>
					<?php }elseif(intval($v['statu'])==1){ ?>
					<td class="statu">
					    <span class="label label-primary">进行中</span>
					</td>
					<td class="operate">
					    <a class="btn btn-default btn-sm" title="完成任务" href="javascript:void(0);" onclick="finish(<?php echo $v['id']; ?>, this)">完成</a>
						<a class="btn btn-default btn-sm" title="查看任务" href="javascript:void(0);" onclick="view(<?php echo $v['id']; ?>)">查看</a>
						<a class="btn btn-default btn-sm" title="任务备注" href="/office/memo?id=<?php echo $v['id'];?>">备注</a>
					</td>
					<?php }elseif(intval($v['statu'])==2){ ?>
					<td class="statu">
					    <span class="label label-success">已完成</span>
					</td>
					<td class="operate">
					    <a class="btn btn-default btn-sm" title="查看任务" href="javascript:void(0);" onclick="view(<?php echo $v['id']; ?>)">查看</a>
					    <a class="btn btn-default btn-sm" title="任务备注" href="/office/memo?id=<?php echo $v['id'];?>">备注</a>
					</td>
					<?php }?>
				</tr>
			    <?php endforeach;?> 
			    <?php endif;?>
			    <tr>
					<td colspan="7">
			            <?php echo $this->paginationControl ( $this->paginator, 'Sliding', 'page/qaitem.phtml', array (
			            		'title' => $this->title,
					     	    'statu'=>$this->statu,
						        'starttime' => $this->starttime,
						        'endtime' => $this->endtime) 
			            );?>
			        </td>
				</tr>
			</tbody>
		</table>
		<div class="col-md-3">
		    <div class="panel panel-default">
				<div class="panel-heading">
					<div class="panel-btns">
						<a href="" class="minimize">&minus;</a>
					</div>
					<h4 class="panel-title">COOL默认等待</h4>
					<p></p>
				</div>
				<div class="panel-body">
				    <?php 
				    foreach ($this->tblist as $tbv){
				    	if($tbv['priority'] == 0 ){
				    ?>
					<div class="alert alert-info">
						<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
						<div>网站：<?php echo substr($tbv['site'],0,-4); ?></div>
						<div><a href="#">内容：<?php echo $tbv['title']; ?></a></div>
						<div>来自：<?php echo $tbv['need_name']; ?></div>
						<div>时间：<?php echo $tbv['asign_time']; ?></div>
					</div>
					<?php } } ?>
				</div>
			</div>
		</div>
		<div class="col-md-3">
			<div class="panel panel-default">
				<div class="panel-heading">
					<div class="panel-btns">
						<a href="" class="minimize">&minus;</a>
					</div>
					<h4 class="panel-title">WARM比较重要</h4>
					<p></p>
				</div>
				<div class="panel-body">
				    <?php 
				    foreach ($this->tblist as $tbv){
				    	if($tbv['priority'] == 1 ){
				    ?>
					<div class="alert alert-warning">
						<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
						<div>网站：<?php echo substr($tbv['site'],0,-4); ?></div>
						<div><a href="#">内容：<?php echo $tbv['title']; ?></a></div>
						<div>来自：<?php echo $tbv['need_name']; ?></div>
						<div>时间：<?php echo $tbv['asign_time']; ?></div>
					</div>
					<?php } } ?>
				</div>
			</div>
		</div>
		<div class="col-md-3">
			<div class="panel panel-default">
				<div class="panel-heading">
					<div class="panel-btns">
						<a href="" class="minimize">&minus;</a>
					</div>
					<h4 class="panel-title">HOT十分紧急</h4>
					<p></p>
				</div>
				<div class="panel-body">
				    <?php 
				    foreach ($this->tblist as $tbv){
				    	if($tbv['priority'] == 2 ){
				    ?>
					<div class="alert alert-danger">
						<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
						<div>网站：<?php echo substr($tbv['site'],0,-4); ?></div>
						<div><a href="#">内容：<?php echo $tbv['title']; ?></a></div>
						<div>来自：<?php echo $tbv['need_name']; ?></div>
						<div>时间：<?php echo $tbv['asign_time']; ?></div>
					</div>
					<?php } } ?>
				</div>
			</div>
		</div>
		<div class="col-md-3">
			<div class="panel panel-default">
				<div class="panel-heading">
					<div class="panel-btns">
						<a href="" class="minimize">&minus;</a>
					</div>
					<h4 class="panel-title">Doing进行中</h4>
					<p></p>
				</div>
				<div class="panel-body">
				    <?php 
				    foreach ($this->tflist as $tfv){
				    ?>
					<div class="alert alert-success">
						<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
						<div>网站：<?php echo substr($tfv['site'],0,-4); ?></div>
						<div><a href="#">内容：<?php echo $tfv['title']; ?></a></div>
						<div>来自：<?php echo $tfv['need_name']; ?></div>
						<div>时间：<?php echo $tfv['asign_time']; ?></div>
					</div>
					<?php } ?>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="modal" tabindex="-1" style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content">
            
        </div>
   </div>
</div>
<div class="in"></div>
<script type="text/javascript">
$(document).ready(function(){
	$(".modal-header .close").live('click',function(){
		$(".modal").hide();
		$(".in").removeClass("modal-backdrop");
	});
});
//开始任务
function begin(id, obj) {
    if (confirm('确认开始?')) {
        $("#loader").show();
        $.ajax({
            type: "get",
            url: "/office/begin?id="+id,
            data: {},
            success: function(data) {
                switch(data) {
                    case "1":
                        $("#loader").hide();
                        $(obj).parent().parent().children('.statu').html('<span class="label label-primary">进行中</span>');
                        $(obj).parent().parent().children('.operate').html('<a class="btn btn-default btn-sm" title="完成任务" href="javascript:void(0);" onclick="finish('+id+', this)">完成</a><a class="btn btn-default btn-sm" title="查看任务" href="javascript:void(0);" onclick="view('+id+')">查看</a><a class="btn btn-default btn-sm" title="任务备注" href="/office/memo?id='+id+'">备注</a>');
                        //window.location.reload();
                        break;
        			default:alert('任务状态改变失败');
        		}
        	}
        });
    }
}
//完成任务
function finish(id, obj) {
    if (confirm('确定完成?')) {
        $("#loader").show();
        $.ajax({
            type: "get",
            url: "/office/finish?id="+id,
            data: {},
            success: function(data) {
                switch(data) {
                    case "1":
                        $("#loader").hide();
                        $(obj).parent().parent().children('.statu').html('<span class="label label-success">已完成</span>');
                        $(obj).parent().parent().children('.operate').html('<a class="btn btn-default btn-sm" title="查看任务" href="javascript:void(0);" onclick="view('+id+')">查看</a><a class="btn btn-default btn-sm" title="任务备注" href="/office/memo?id='+id+'">备注</a>');
                        //window.location.reload();
                        break;
        			default:alert('任务状态改变失败');
        		}
        	}
        });
    }
}
function view(id) {
	$.get("/office/viewqaitem", {id:id},
	    function(data){
	        $('.modal-content').html(data.html);
	        $(".modal").show();
		    $(".in").addClass("modal-backdrop");
		},'json'
	);
}
</script>